import { TableLabelEnhancerOptions, defaultOptions } from "./tableLabelEnhancerOptions";

export class TableLabelEnhancer{
    table:HTMLTableElement;
    options: TableLabelEnhancerOptions;
    constructor(table:HTMLTableElement, options?:TableLabelEnhancerOptions){
        this.table = table;
        this.options = options || defaultOptions;
    }
    rearrangeTableRows(indexes: number[]): void {
        const rows = Array.from(this.table.rows);
        if(rows.length === 0) return;
        if(indexes.length != rows.length) return;
        if(indexes.some(i => i >= rows.length)) return;
        const sortedRows = indexes.map(index => rows[index]);
        this.table.innerHTML = '';
        sortedRows.forEach(row => {
            this.table.appendChild(row);
        });
    }
}